<?php

namespace Wechat\Controller;

class BaseController extends \Think\Controller{
	protected $w_id = 1;
	protected $user = [];
	protected function init() {
		$wid = session('w_id');
		if (empty($wid)) {
			header('Location: ' . U('index/choose_w'));
		}
		$this->w_id = $wid;
	}
	protected function auth() {
		$is_login = session('is_login');
		if ($is_login) {
			$this->user = session('user');
		}
		return isset($is_login) ? $is_login : FALSE;
	}
	
	/**
     * 数据列表及分页
     * @param mixed $where 查询条件
     * @param int $pageSize 页大小
     * @param string $order 排序
     * @return array array('data'=>数据列表,'page'=>分页)
     */
    protected function getPager($model,$where=array(),$pageSize=10,$order='id desc'){
        I('get.p') ? $p=I('get.p') : $p=1;
        $list = $model->where($where)->order($order)->page($p.','.$pageSize)->select();
        $count = $model->where($where)->count();
        $Page = new \Think\Page($count,$pageSize);
        $show = $Page->show();
        return array(
            'data' => $list,
            'page' => $show,
        );
    }
}